/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package webapps.tools;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;

/**
 *
 * @author Adrien
 */
public class Paginer<T> {
    
    List<T> listes;

    public List<T> getListes() {
        return listes;
    }

    public void setListes(List<T> listes) {
        this.listes = listes;
    }

    public Paginer(List<T> listes) {
        this.listes = listes;
    }
    
    public void render(HttpServletRequest request, JspWriter out)
    {
        //APPLICATION DE LA PAGINATION
        int debut           = 0;
        int nombre_page     = (listes.size() / 30) +1;
        int numero_page     = 1;
        int nombre_resultat = listes.size();

        if (request.getParameter("p") != null && Tools.estEntier(request.getParameter("p")))
        {
            numero_page = Integer.parseInt(request.getParameter("p"));
            debut =  Tools.max(0,(numero_page) - 1) * 30;
        }

        request.setAttribute("clients", listes);
        request.setAttribute("numero_page", numero_page);
        request.setAttribute("nombre_page", nombre_page);
        request.setAttribute("nombre_resultat", nombre_resultat);        
    }
}
